package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hlw.hr_man.service.EmployeeSrevice;
import com.hlw.hr_man.serviceImpl.EmployeeServiceImpl;

import net.sf.json.JSONObject;
/**
 * 查询员工信息
 * @author Windy--Chow
 *
 */
public class SelectEmyployeecontroller extends HttpServlet{
	        EmployeeSrevice employeess = new EmployeeServiceImpl();
            @Override
            protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            	// TODO Auto-generated method stub
            	doPost(req, resp);
            }
            @Override
            protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            // TODO Auto-generated method stub
            	 req.setCharacterEncoding("utf8");
                 resp.setCharacterEncoding("utf8");
                 JSONObject employee = new JSONObject();
                 HttpSession session = req.getSession();
                 PrintWriter pw = resp.getWriter();
                 int page = Integer.parseInt(req.getParameter("page"));
                 int pageSize = Integer.parseInt(req.getParameter("rows"));
                 int start = (page-1)*pageSize;
                 String searchname = req.getParameter("searchname");
                 String searchtype = req.getParameter("searchtype");
            
                 if(searchtype != null){
                	 if("byname".equals(req.getParameter("searchtype"))){      		 
                 		 employee = employeess.findAllEmployee(start, pageSize,searchname);
                	 }
                	 if("bydept".equals(req.getParameter("searchtype"))){
                		 employee = employeess.findAllEmployee(start, pageSize, searchname, searchtype);
                	 }
                 }else{
                	 employee = employeess.findAllEmployee(start, pageSize);
                 }
                 pw.write(employee.toString());
            }
}

